<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'organisation-form',
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

        <fieldset class="box">
	<table>
            <tr class="row">
		<td><?php echo $form->labelEx($model,'anrede'); ?>
		</td><td><?php echo $form->textField($model,'anrede',array('size'=>10,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'anrede'); ?>
    
		<?php echo $form->labelEx($model,'is_group'); ?>
		<?php echo $form->checkBox($model,'is_group'); ?>
		<?php echo $form->error($model,'is_group'); ?>
	</td></tr>
            
            <tr class="row">
                <td>
                    <?php echo $form->labelEx($model,'vorname'); ?>
                </td>
                <td>
                    <?php echo $form->textField($model,'vorname',array('size'=>49,'maxlength'=>45)); ?>
                    <?php echo $form->error($model,'vorname'); ?>
                </td>
	</tr>

	<tr class="row">
		<td><?php echo $form->labelEx($model,'nachname'); ?>
		</td><td><?php echo $form->textField($model,'nachname',array('size'=>49,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'nachname'); ?>
	</td></tr>

	<tr class="row">
		<td><?php echo $form->labelEx($model,'ntname'); ?>
		</td><td><?php echo $form->textField($model,'ntname',array('size'=>49,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'ntname'); ?>
	</td></tr>

	<tr class="row">
		<td><?php echo $form->labelEx($model,'parent_org_id'); ?>
		</td>
                <td>
                    <?php echo $form->hiddenField($model,'parent_org_id'); ?>
                    <?php

                    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                       //'model'=>$model,
                       'name'=>'parent_org_id',
                       'value'=>CHtml::encode(Organisation::model()->findByPK($model->parent_org_id)->nachname),
                       'source' => $this->createUrl('Organisation/autocompleteOrganisation'),
                       'options' => array(
                            'minLength'=>'2',
                            'select'=>"js:function(event,ui){
                                $('#".CHtml::activeId($model,'parent_org_id')."').val(ui.item.id);
                            }",
                       ),
                    ));

                    ?>
                    <?php echo $form->error($model,'parent_org_id'); ?>

                <?php echo $form->labelEx($model,'type'); ?>
		<?php echo $form->dropdownList($model,'type',array('1'=>'Employee','2'=>'Department','3'=>'Organisation')); ?>
		<?php echo $form->error($model,'type'); ?>
	</td></tr>
        
        </table>
        </fieldset>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>"button")); ?>
	</div>

<?php $this->endWidget(); ?>

        <?php

        if(!$model->org_id==''){
            if($model->is_group == 0){
        
                $criteria=new CDbCriteria(array(
                            'condition'=>'org_id = '.$model->org_id,
                        ));

                $dataprovider = new CActiveDataProvider('Kommunikation',
                        array('criteria'=>$criteria));

             //var_dump($dataprovider);

                $this->widget('zii.widgets.jui.CJuiAccordion', array(
                    'panels'=>array(
                        'Communication'=>$this->renderPartial('/kommunikation/subview',array('dataprovider'=>$dataprovider,'org_id'=>$model->org_id),true),
                    ),
                ));

            }else{

                $criteria=new CDbCriteria(array(
                        'condition'=>'tbl_organisation_org_id = '.$model->org_id,
                        'with'=> array('tblOrganisationOrgChild'),
                ));

                $dataprovider=new CActiveDataProvider('OrganisationHasTblOrganisation',array(
                    'criteria'=>$criteria,
                ));

                //hier kommt die implementierung der user zuordnung...
                $this->widget('zii.widgets.jui.CJuiAccordion', array(
                    'panels'=>array(
                        'Assigned User'=>$this->renderPartial('/organisation/subview',array("dataprovider"=>$dataprovider,"tbl_organisation_org_id"=>$model->org_id),true),
                    ),
                ));
            }
        }
        
     ?>


</div><!-- form -->